
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>definition · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="method.html" />
    
    
    <link rel="prev" href="errors.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    快速入门
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../guides/project.html">
            
                <a href="../guides/project.html">
            
                    
                    项目结构和初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../guides/api.html">
            
                <a href="../guides/api.html">
            
                    
                    API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../guides/doc.html">
            
                <a href="../guides/doc.html">
            
                    
                    生成 API 文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../guides/client.html">
            
                <a href="../guides/client.html">
            
                    
                    生成客户端
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    概念
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../concepts/cp.html">
            
                <a href="../concepts/cp.html">
            
                    
                    Consumer && Producer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../concepts/operator.html">
            
                <a href="../concepts/operator.html">
            
                    
                    Operator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../concepts/filter.html">
            
                <a href="../concepts/filter.html">
            
                    
                    Filter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../concepts/prefab.html">
            
                <a href="../concepts/prefab.html">
            
                    
                    Prefab
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../concepts/modifier.html">
            
                <a href="../concepts/modifier.html">
            
                    
                    Modifier
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../concepts/middleware.html">
            
                <a href="../concepts/middleware.html">
            
                    
                    Middleware
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../concepts/context.html">
            
                <a href="../concepts/context.html">
            
                    
                    Context
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../concepts/source.html">
            
                <a href="../concepts/source.html">
            
                    
                    Parameter Generator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../concepts/destination.html">
            
                <a href="../concepts/destination.html">
            
                    
                    Destination Handler
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../concepts/error.html">
            
                <a href="../concepts/error.html">
            
                    
                    错误包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../concepts/method.html">
            
                <a href="../concepts/method.html">
            
                    
                    方法包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../concepts/configurer.html">
            
                <a href="../concepts/configurer.html">
            
                    
                    配置器机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="../concepts/plugin.html">
            
                <a href="../concepts/plugin.html">
            
                    
                    插件机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.14" data-path="../concepts/clients.html">
            
                <a href="../concepts/clients.html">
            
                    
                    多客户端整合
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    插件
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../plugins/logger.html">
            
                <a href="../plugins/logger.html">
            
                    
                    系统日志插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../plugins/reqlog.html">
            
                <a href="../plugins/reqlog.html">
            
                    
                    请求日志插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../plugins/metrics.html">
            
                <a href="../plugins/metrics.html">
            
                    
                    监控指标插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../plugins/tracing.html">
            
                <a href="../plugins/tracing.html">
            
                    
                    请求追踪插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../plugins/profiling.html">
            
                <a href="../plugins/profiling.html">
            
                    
                    性能分析插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../plugins/version.html">
            
                <a href="../plugins/version.html">
            
                    
                    版本信息插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../plugins/healthcheck.html">
            
                <a href="../plugins/healthcheck.html">
            
                    
                    健康检查插件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    框架开发者指南
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="start.html">
            
                <a href="start.html">
            
                    
                    准备工作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="log.html">
            
                <a href="log.html">
            
                    
                    log
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="errors.html">
            
                <a href="errors.html">
            
                    
                    errors
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.4" data-path="definition.html">
            
                <a href="definition.html">
            
                    
                    definition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="method.html">
            
                <a href="method.html">
            
                    
                    definition/method
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="converter.html">
            
                <a href="converter.html">
            
                    
                    operators/converter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="validator.html">
            
                <a href="validator.html">
            
                    
                    operators/validator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="router.html">
            
                <a href="router.html">
            
                    
                    service/router
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="service.html">
            
                <a href="service.html">
            
                    
                    service
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="nirvana.html">
            
                <a href="nirvana.html">
            
                    
                    nirvana
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.11" data-path="config.html">
            
                <a href="config.html">
            
                    
                    config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.12" data-path="rest.html">
            
                <a href="rest.html">
            
                    
                    rest
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.13" data-path="utils.html">
            
                <a href="utils.html">
            
                    
                    utils
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.14" data-path="command.html">
            
                <a href="command.html">
            
                    
                    cmd/nirvana
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >definition</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="definition-&#x5305;">definition &#x5305;</h1>
<p>definition &#x5305;&#x5305;&#x542B;&#x4E86; Nirvana &#x7684; API &#x5B9A;&#x4E49;&#xFF0C;&#x7528;&#x4E8E;&#x63CF;&#x8FF0; API &#x7684;&#x53C2;&#x6570;&#x4E0E;&#x8FD4;&#x56DE;&#x503C;&#x3002;</p>
<pre><code class="lang-go"><span class="hljs-comment">// Chain contains all subsequent actions.</span>
<span class="hljs-keyword">type</span> Chain <span class="hljs-keyword">interface</span> {
    <span class="hljs-comment">// Continue continues to execute the next subsequent actions.</span>
    Continue(context.Context) error
}

<span class="hljs-comment">// Middleware describes the form of middlewares. If you want to</span>
<span class="hljs-comment">// carry on, call Chain.Continue() and pass the context.</span>
<span class="hljs-keyword">type</span> Middleware <span class="hljs-keyword">func</span>(context.Context, Chain) error

<span class="hljs-comment">// Operator is used to operate an object and return an replacement object.</span>
<span class="hljs-comment">//</span>
<span class="hljs-comment">// For example:</span>
<span class="hljs-comment">//  A converter:</span>
<span class="hljs-comment">//    type ConverterForAnObject struct{}</span>
<span class="hljs-comment">//    func (c *ConverterForAnObject) Kind() {return &quot;converter&quot;}</span>
<span class="hljs-comment">//    func (c *ConverterForAnObject) In() reflect.Type {return definition.TypeOf(&amp;ObjectV1{})}</span>
<span class="hljs-comment">//    func (c *ConverterForAnObject) Out() reflect.Type {return definition.TypeOf(&amp;ObjectV2{})}</span>
<span class="hljs-comment">//    func (c *ConverterForAnObject) Operate(ctx context.Context, object interface{}) (interface{}, error) {</span>
<span class="hljs-comment">//        objV2, err := convertObjectV1ToObjectV2(object.(*ObjectV1))</span>
<span class="hljs-comment">//        return objV2, err</span>
<span class="hljs-comment">//    }</span>
<span class="hljs-comment">//</span>
<span class="hljs-comment">//  A validator:</span>
<span class="hljs-comment">//    type ValidatorForAnObject struct{}</span>
<span class="hljs-comment">//    func (c *ValidatorForAnObject) Kind() {return &quot;validator&quot;}</span>
<span class="hljs-comment">//    func (c *ValidatorForAnObject) In() reflect.Type {return definition.TypeOf(&amp;Object{})}</span>
<span class="hljs-comment">//    func (c *ValidatorForAnObject) Out() reflect.Type {return definition.TypeOf(&amp;Object{})}</span>
<span class="hljs-comment">//    func (c *ValidatorForAnObject) Operate(ctx context.Context, object interface{}) (interface{}, error) {</span>
<span class="hljs-comment">//        if err := validate(object.(*Object)); err != nil {</span>
<span class="hljs-comment">//            return nil, err</span>
<span class="hljs-comment">//        }</span>
<span class="hljs-comment">//        return object, nil</span>
<span class="hljs-comment">//    }</span>
<span class="hljs-keyword">type</span> Operator <span class="hljs-keyword">interface</span> {
    <span class="hljs-comment">// Kind indicates operator type.</span>
    Kind() <span class="hljs-keyword">string</span>
    <span class="hljs-comment">// In returns the type of the only object parameter of operator.</span>
    <span class="hljs-comment">// The type must be a concrete struct or built-in type. It should</span>
    <span class="hljs-comment">// not be interface unless it&apos;s a file or stream reader.</span>
    In() reflect.Type
    <span class="hljs-comment">// Out returns the type of the only object result of operator.</span>
    <span class="hljs-comment">// The type must be a concrete struct or built-in type. It should</span>
    <span class="hljs-comment">// not be interface unless it&apos;s a file or stream reader.</span>
    Out() reflect.Type
    <span class="hljs-comment">// Operate operates an object and return one.</span>
    Operate(ctx context.Context, field <span class="hljs-keyword">string</span>, object <span class="hljs-keyword">interface</span>{}) (<span class="hljs-keyword">interface</span>{}, error)
}

<span class="hljs-comment">// Method is an alternative of HTTP method. It&apos;s more clearer than HTTP method.</span>
<span class="hljs-comment">// A definition method binds a certain HTTP method and a success status code.</span>
<span class="hljs-keyword">type</span> Method <span class="hljs-keyword">string</span>

<span class="hljs-keyword">const</span> (
    <span class="hljs-comment">// List binds to http.MethodGet and code http.StatusOK(200).</span>
    List Method = <span class="hljs-string">&quot;List&quot;</span>
    <span class="hljs-comment">// Get binds to http.MethodGet and code http.StatusOK(200).</span>
    Get Method = <span class="hljs-string">&quot;Get&quot;</span>
    <span class="hljs-comment">// Create binds to http.MethodPost and code http.StatusCreated(201).</span>
    Create Method = <span class="hljs-string">&quot;Create&quot;</span>
    <span class="hljs-comment">// Update binds to http.MethodPut and code http.StatusOK(200).</span>
    Update Method = <span class="hljs-string">&quot;Update&quot;</span>
    <span class="hljs-comment">// Patch binds to http.MethodPatch and code http.StatusOK(200).</span>
    Patch Method = <span class="hljs-string">&quot;Patch&quot;</span>
    <span class="hljs-comment">// Delete binds to http.MethodDelete and code http.StatusNoContent(204).</span>
    Delete Method = <span class="hljs-string">&quot;Delete&quot;</span>
    <span class="hljs-comment">// AsyncCreate binds to http.MethodPost and code http.StatusAccepted(202).</span>
    AsyncCreate Method = <span class="hljs-string">&quot;AsyncCreate&quot;</span>
    <span class="hljs-comment">// AsyncUpdate binds to http.MethodPut and code http.StatusAccepted(202).</span>
    AsyncUpdate Method = <span class="hljs-string">&quot;AsyncUpdate&quot;</span>
    <span class="hljs-comment">// AsyncPatch binds to http.MethodPatch and code http.StatusAccepted(202).</span>
    AsyncPatch Method = <span class="hljs-string">&quot;AsyncPatch&quot;</span>
    <span class="hljs-comment">// AsyncDelete binds to http.MethodDelete and code http.StatusAccepted(202).</span>
    AsyncDelete Method = <span class="hljs-string">&quot;AsyncDelete&quot;</span>
)

<span class="hljs-comment">// Source indicates which place a value is from.</span>
<span class="hljs-keyword">type</span> Source <span class="hljs-keyword">string</span>

<span class="hljs-keyword">const</span> (
    <span class="hljs-comment">// Path means value is from URL path.</span>
    Path Source = <span class="hljs-string">&quot;Path&quot;</span>
    <span class="hljs-comment">// Query means value is from URL query string.</span>
    Query Source = <span class="hljs-string">&quot;Query&quot;</span>
    <span class="hljs-comment">// Header means value is from request header.</span>
    Header Source = <span class="hljs-string">&quot;Header&quot;</span>
    <span class="hljs-comment">// Form means value is from request body and content type must be</span>
    <span class="hljs-comment">// &quot;application/x-www-form-urlencoded&quot; and &quot;multipart/form-data&quot;.</span>
    Form Source = <span class="hljs-string">&quot;Form&quot;</span>
    <span class="hljs-comment">// File means value is from request body and content type must be</span>
    <span class="hljs-comment">// &quot;multipart/form-data&quot;.</span>
    File Source = <span class="hljs-string">&quot;File&quot;</span>
    <span class="hljs-comment">// Body means value is from request body.</span>
    Body Source = <span class="hljs-string">&quot;Body&quot;</span>
    <span class="hljs-comment">// Auto identifies a struct and generate field values by field tag.</span>
    <span class="hljs-comment">//</span>
    <span class="hljs-comment">// Tag name is &quot;source&quot;. Its value format is &quot;Source,Name&quot;.</span>
    <span class="hljs-comment">//</span>
    <span class="hljs-comment">// ex.</span>
    <span class="hljs-comment">// type Example struct {</span>
    <span class="hljs-comment">//     Start       int    `source:&quot;Query,start&quot;`</span>
    <span class="hljs-comment">//     ContentType string `source:&quot;Header,Content-Type&quot;`</span>
    <span class="hljs-comment">// }</span>
    Auto Source = <span class="hljs-string">&quot;Auto&quot;</span>
    <span class="hljs-comment">// Prefab means value is from a prefab generator.</span>
    <span class="hljs-comment">// A prefab combines data to generate value.</span>
    Prefab Source = <span class="hljs-string">&quot;Prefab&quot;</span>
)

<span class="hljs-comment">// Destination indicates the target type to place function results.</span>
<span class="hljs-keyword">type</span> Destination <span class="hljs-keyword">string</span>

<span class="hljs-keyword">const</span> (
    <span class="hljs-comment">// Meta means result will be set into the header of response.</span>
    Meta Destination = <span class="hljs-string">&quot;Meta&quot;</span>
    <span class="hljs-comment">// Data means result will be set into the body of response.</span>
    Data Destination = <span class="hljs-string">&quot;Data&quot;</span>
    <span class="hljs-comment">// Error means the result is an error and should be treated specially.</span>
    <span class="hljs-comment">// An error occurs indicates that there is no data to return. So the</span>
    <span class="hljs-comment">// error should be treated as data and be writed back to client.</span>
    Error Destination = <span class="hljs-string">&quot;Error&quot;</span>
)

<span class="hljs-comment">// Example is just an example.</span>
<span class="hljs-keyword">type</span> Example <span class="hljs-keyword">struct</span> {
    <span class="hljs-comment">// Description describes the example.</span>
    Description <span class="hljs-keyword">string</span>
    <span class="hljs-comment">// Instance is a custom data.</span>
    Instance <span class="hljs-keyword">interface</span>{}
}

<span class="hljs-comment">// Parameter describes a function parameter.</span>
<span class="hljs-keyword">type</span> Parameter <span class="hljs-keyword">struct</span> {
    <span class="hljs-comment">// Source is the parameter value generated from.</span>
    Source Source
    <span class="hljs-comment">// Name is the name to get value from a request.</span>
    <span class="hljs-comment">// ex. a query name, a header key, etc.</span>
    Name <span class="hljs-keyword">string</span>
    <span class="hljs-comment">// Default value is used when a request does not provide a value</span>
    <span class="hljs-comment">// for the parameter.</span>
    Default <span class="hljs-keyword">interface</span>{}
    <span class="hljs-comment">// Operators can modify and validate the target value.</span>
    <span class="hljs-comment">// Parameter value is passed to the first operator, then</span>
    <span class="hljs-comment">// previous operator&apos;s result is as next operator&apos;s parameter.</span>
    <span class="hljs-comment">// The result of last operator will be passed to target function.</span>
    Operators []Operator
    <span class="hljs-comment">// Description describes the parameter.</span>
    Description <span class="hljs-keyword">string</span>
}

<span class="hljs-comment">// Result describes how to handle a result from function results.</span>
<span class="hljs-keyword">type</span> Result <span class="hljs-keyword">struct</span> {
    <span class="hljs-comment">// Destination is the target for the result. Different types make different behavior.</span>
    Destination Destination
    <span class="hljs-comment">// Operators can modify the result value.</span>
    <span class="hljs-comment">// Result value is passed to the first operator, then</span>
    <span class="hljs-comment">// previous operator&apos;s result is as next operator&apos;s parameter.</span>
    <span class="hljs-comment">// The result of last operator will be passed to destination handler.</span>
    Operators []Operator
    <span class="hljs-comment">// Description describes the result.</span>
    Description <span class="hljs-keyword">string</span>
}

<span class="hljs-comment">// Definition defines an API handler.</span>
<span class="hljs-keyword">type</span> Definition <span class="hljs-keyword">struct</span> {
    <span class="hljs-comment">// Method is definition method.</span>
    Method Method
    <span class="hljs-comment">// Consumes indicates how many content types the handler can consume.</span>
    <span class="hljs-comment">// It will override parent descriptor&apos;s consumes.</span>
    Consumes []<span class="hljs-keyword">string</span>
    <span class="hljs-comment">// Produces indicates how many content types the handler can produce.</span>
    <span class="hljs-comment">// It will override parent descriptor&apos;s produces.</span>
    Produces []<span class="hljs-keyword">string</span>
    <span class="hljs-comment">// ErrorProduces is used to generate data for error. If this field is empty,</span>
    <span class="hljs-comment">// it means that this field equals to Produces.</span>
    <span class="hljs-comment">// In some cases, succeessful data and error data should be generated in</span>
    <span class="hljs-comment">// different ways.</span>
    ErrorProduces []<span class="hljs-keyword">string</span>
    <span class="hljs-comment">// Function is a function handler. It must be func type.</span>
    Function <span class="hljs-keyword">interface</span>{}
    <span class="hljs-comment">// Parameters describes function parameters.</span>
    Parameters []Parameter
    <span class="hljs-comment">// Results describes function retrun values.</span>
    Results []Result
    <span class="hljs-comment">// Summary is a one-line brief description of this definition.</span>
    Summary <span class="hljs-keyword">string</span>
    <span class="hljs-comment">// Description describes the API handler.</span>
    Description <span class="hljs-keyword">string</span>
    <span class="hljs-comment">// Examples contains many examples for the API handler.</span>
    Examples []Example
}

<span class="hljs-comment">// Descriptor describes a descriptor for API definitions.</span>
<span class="hljs-keyword">type</span> Descriptor <span class="hljs-keyword">struct</span> {
    <span class="hljs-comment">// Path is the url path. It will inherit parent&apos;s path.</span>
    <span class="hljs-comment">//</span>
    <span class="hljs-comment">// If parent path is &quot;/api/v1&quot;, current is &quot;/some&quot;,</span>
    <span class="hljs-comment">// It means current definitions handles &quot;/api/v1/some&quot;.</span>
    Path <span class="hljs-keyword">string</span>
    <span class="hljs-comment">// Consumes indicates content types that current definitions</span>
    <span class="hljs-comment">// and child definitions can consume.</span>
    <span class="hljs-comment">// It will override parent descriptor&apos;s consumes.</span>
    Consumes []<span class="hljs-keyword">string</span>
    <span class="hljs-comment">// Produces indicates content types that current definitions</span>
    <span class="hljs-comment">// and child definitions can produce.</span>
    <span class="hljs-comment">// It will override parent descriptor&apos;s produces.</span>
    Produces []<span class="hljs-keyword">string</span>
    <span class="hljs-comment">// Middlewares contains path middlewares.</span>
    Middlewares []Middleware
    <span class="hljs-comment">// Definitions contains definitions for current path.</span>
    Definitions []Definition
    <span class="hljs-comment">// Children is used to place sub-descriptors.</span>
    Children []Descriptor
    <span class="hljs-comment">// Description describes the usage of the path.</span>
    Description <span class="hljs-keyword">string</span>
}
</code></pre>
<p>Descriptor &#x7ED3;&#x6784;&#x4F53;&#x5305;&#x542B;&#x5177;&#x6709;&#x5982;&#x4E0B;&#x542B;&#x4E49;&#x7684;&#x5B57;&#x6BB5;&#xFF1A;</p>
<ol>
<li>API &#x8DEF;&#x5F84;</li>
<li>&#x53EF;&#x88AB; Middlewares&#xFF0C;Definitions&#xFF0C;Children &#x7EE7;&#x627F;&#x7684;&#x5B57;&#x6BB5;</li>
<li>&#x5176;&#x4ED6;&#x4E0E; API &#x8DEF;&#x5F84;&#x540C;&#x7B49;&#x7EA7;&#x522B;&#x7684;&#x5B57;&#x6BB5;</li>
</ol>
<p>&#x5982;&#x679C;&#x5E0C;&#x671B;&#x5BF9; Descriptor &#x8FDB;&#x884C;&#x6269;&#x5C55;&#xFF0C;&#x9700;&#x8981;&#x9075;&#x5B88;&#x4E0A;&#x9762;&#x8FD9;&#x4E9B;&#x89C4;&#x5219;&#x3002;</p>
<p>Definition &#x7ED3;&#x6784;&#x4F53;&#x5305;&#x542B;&#x4E86;&#x4E00;&#x4E2A;&#x5177;&#x4F53;&#x7684; API &#x5B9A;&#x4E49;&#xFF1A;</p>
<ol>
<li>API &#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#xFF0C;&#x7528;&#x4E8E;&#x63CF;&#x8FF0;&#x4E00;&#x79CD;&#x884C;&#x4E3A;&#xFF08;&#x6BD4;&#x5982; Create&#xFF09;&#x3002;</li>
<li>API &#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#x5B9A;&#x4E49;</li>
<li>&#x5176;&#x4ED6;&#x4E0E;&#x5177;&#x4F53; API &#x540C;&#x7B49;&#x7EA7;&#x522B;&#x7684;&#x5B57;&#x6BB5;</li>
</ol>
<p>&#x5982;&#x679C;&#x5E0C;&#x671B;&#x5BF9; Definition &#x8FDB;&#x884C;&#x6269;&#x5C55;&#xFF0C;&#x9700;&#x8981;&#x9075;&#x5B88;&#x4E0A;&#x9762;&#x8FD9;&#x4E9B;&#x89C4;&#x5219;&#x3002;</p>
<p>Parameter &#x548C; Result &#x5206;&#x522B;&#x5BF9;&#x5E94; API &#x7684;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x4E0E;&#x4E1A;&#x52A1;&#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570;&#x4E0E;&#x8FD4;&#x56DE;&#x503C;&#x4E00;&#x4E00;&#x5BF9;&#x5E94;&#x3002;&#x5B57;&#x6BB5;&#x5B9A;&#x4E49;&#x4E0E;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#x7684;&#x8F6C;&#x6362;&#x6709;&#x5173;&#x3002;</p>
<p>&#x5728;&#x4E0A;&#x9762;&#x7684;&#x5B9A;&#x4E49;&#x4E2D;&#xFF0C;&#x5B58;&#x5728;&#x4E24;&#x4E2A;&#x989D;&#x5916;&#x529F;&#x80FD;&#xFF1A;</p>
<ol>
<li>&#x5728; Descriptor &#x4E2D;&#x63D0;&#x4F9B;&#x4E86; Middleware</li>
<li>&#x5728; Parameter &#x548C; Result &#x4E2D;&#xFF0C;&#x63D0;&#x4F9B;&#x4E86; Operator</li>
</ol>
<p>&#x5176;&#x4E2D; Middleware &#x63D0;&#x4F9B;&#x4E86;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x80FD;&#x529B;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x8BF7;&#x6C42;&#x4E4B;&#x524D;&#x8BA9;&#x7528;&#x6237;&#x5BF9;&#x8BF7;&#x6C42;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x7279;&#x6B8A;&#x5904;&#x7406;&#x3002;&#x800C; Operator &#x5219;&#x9488;&#x5BF9;&#x5355;&#x4E2A;&#x7684;&#x4E1A;&#x52A1;&#x53C2;&#x6570;&#x548C;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x5BF9;&#x503C;&#x8FDB;&#x884C;&#x9A8C;&#x8BC1;&#x548C;&#x4FEE;&#x6539;&#x3002;</p>
<p>definition &#x5305;&#x9664;&#x4E86;&#x5305;&#x542B;&#x5BF9; API &#x7684;&#x5B9A;&#x4E49;&#x4EE5;&#x5916;&#xFF0C;&#x8FD8;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E9B;&#x51FD;&#x6570;&#xFF0C;&#x5E2E;&#x52A9;&#x5FEB;&#x901F;&#x6784;&#x5EFA; Definitions &#x548C; Operators&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-comment">// MIME types</span>
<span class="hljs-keyword">const</span> (
    <span class="hljs-comment">// acceptTypeAll indicates a accept type from http request.</span>
    <span class="hljs-comment">// It means client can receive any content.</span>
    <span class="hljs-comment">// Request content type in header &quot;Content-Type&quot; must not set to &quot;*/*&quot;.</span>
    <span class="hljs-comment">// It only can exist in request header &quot;Accept&quot;.</span>
    <span class="hljs-comment">// In most time, it locate at the last element of &quot;Accept&quot;.</span>
    <span class="hljs-comment">// It&apos;s default value if client have not set &quot;Accept&quot; header.</span>
    MIMEAll         = <span class="hljs-string">&quot;*/*&quot;</span>
    MIMENone        = <span class="hljs-string">&quot;&quot;</span>
    MIMEText        = <span class="hljs-string">&quot;text/plain&quot;</span>
    MIMEJSON        = <span class="hljs-string">&quot;application/json&quot;</span>
    MIMEXML         = <span class="hljs-string">&quot;application/xml&quot;</span>
    MIMEOctetStream = <span class="hljs-string">&quot;application/octet-stream&quot;</span>
    MIMEURLEncoded  = <span class="hljs-string">&quot;application/x-www-form-urlencoded&quot;</span>
    MIMEFormData    = <span class="hljs-string">&quot;multipart/form-data&quot;</span>
)

<span class="hljs-comment">// OperatorFunc creates operator by function.</span>
<span class="hljs-comment">// function must has signature:</span>
<span class="hljs-comment">//  func f(context.Context, string, AnyType) (AnyType, error)</span>
<span class="hljs-comment">// The second parameter is a string that is used to identify field.</span>
<span class="hljs-comment">// AnyType can be any type in go. But struct type and</span>
<span class="hljs-comment">// built-in data type is recommended.</span>
<span class="hljs-keyword">func</span> OperatorFunc(kind <span class="hljs-keyword">string</span>, f <span class="hljs-keyword">interface</span>{}) Operator
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="errors.html" class="navigation navigation-prev " aria-label="Previous page: errors">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="method.html" class="navigation navigation-next " aria-label="Next page: definition/method">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"definition","level":"1.5.4","depth":2,"next":{"title":"definition/method","level":"1.5.5","depth":2,"path":"topics/method.md","ref":"topics/method.md","articles":[]},"previous":{"title":"errors","level":"1.5.3","depth":2,"path":"topics/errors.md","ref":"topics/errors.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"zh-hans","gitbook":"*"},"file":{"path":"topics/definition.md","mtime":"2019-08-06T09:48:58.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-10-20T10:33:16.586Z"},"basePath":"..","book":{"language":"zh-hans"}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

